#ifndef __OF_FDT_H__
#define __OF_FDT_H__

#include "linux/of.h"
#include "linux/types.h"

/* Definitions used by the flattened device tree */
#define OF_DT_HEADER		0xd00dfeed	/* marker */

#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1

/* For scanning an arbitrary device-tree at any time */
extern char *of_fdt_get_string( void *blob, uint32_t offset);
extern void *of_fdt_get_property( void *blob,
				 unsigned long node,
				  char *name,
				 int *size);
extern int of_fdt_is_compatible( void *blob,
				unsigned long node,
				 char *compat);
extern int of_fdt_is_big_endian( void *blob,
				 unsigned long node);
extern int of_fdt_match(void *blob, unsigned long node, char **compat);
extern void *of_fdt_unflatten_tree( unsigned long *blob,
				   struct device_node *dad,
				   struct device_node **mynodes);

/* TBD: Temporary export of fdt globals - remove when code fully merged */
extern int dt_root_addr_cells;
extern int dt_root_size_cells;
extern void *initial_boot_params;

extern char __dtb_start[];
extern char __dtb_end[];

/* For scanning the flat device-tree at boot time */
extern int of_scan_flat_dt(int (*it)(unsigned long node, char *uname, int depth, void *data), void *data);
extern int of_get_flat_dt_subnode_by_name(unsigned long node,
					   char *uname);
extern void *of_get_flat_dt_prop(unsigned long node,  char *name,  int *size);
extern int of_flat_dt_is_compatible(unsigned long node,  char *name);
extern int of_flat_dt_match(unsigned long node,  char * *matches);
extern unsigned long of_get_flat_dt_root(void);
extern int of_get_flat_dt_size(void);

extern int early_init_dt_scan_chosen(unsigned long node,  char *uname, int depth, void *data);
extern int early_init_dt_scan_memory(unsigned long node,  char *uname, int depth, void *data);
extern int early_init_dt_scan_chosen_stdout(void);
extern void early_init_fdt_scan_reserved_mem(void);
extern void early_init_fdt_reserve_self(void);
extern void early_init_dt_add_memory_arch(uint64_t base, uint64_t size);
extern int early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size);
extern void * early_init_dt_alloc_memory_arch(uint64_t size, uint64_t align);
extern uint64_t dt_mem_next_cell(int s,  uint32_t **cellp);

/* Early flat tree scan hooks */
extern int early_init_dt_scan_root(unsigned long node,  char *uname,
				   int depth, void *data);

extern int early_init_dt_scan(void *params);
extern int early_init_dt_verify(void *params);
extern void early_init_dt_scan_nodes(void);

extern char *of_flat_dt_get_machine_name(void);
extern void *of_flat_dt_match_machine(void *default_match, void * (*get_next_compat)(char ***));

/* Other Prototypes */
extern void unflatten_device_tree(void);
extern void unflatten_and_copy_device_tree(void);
extern void early_init_devtree(void *);
extern void early_get_first_memblock_info(void *, phys_addr_t *);
extern uint64_t of_flat_dt_translate_address(unsigned long node);
extern void of_fdt_limit_memory(int limit);
extern char *of_node_full_name( struct device_node *np);

#endif
